﻿
using System.ComponentModel;

namespace WD.Db.Contract
{
    public partial class CommonCode
    {
        /// <summary>            
        /// 信息框显示操作结果  100 
        /// </summary>
        public readonly static string Json结果代码_statusCode_信息 = "100";
        /// <summary>
        /// 成功框显示操作结果  200
        /// </summary>
        public readonly static string Json结果代码_statusCode_成功 = "200";
        /// <summary>
        /// 错误框显示操作结果  300
        /// </summary>
        public readonly static string Json结果代码_statusCode_错误 = "300";
        /// <summary>
        /// 警告框显示操作结果  400
        /// </summary>
        public readonly static string Json结果代码_statusCode_警告 = "400";
        /// <summary>
        /// 弹出登录框重新登录  301
        /// </summary>
        public readonly static string Json结果代码_statusCode_登录超时 = "301";
        /// <summary>
        /// 查询成功（无弹框）  201
        /// </summary>
        public readonly static string Json结果代码_statusCode_查询成功 = "201";
        /// <summary>
        /// 关闭当前对话框  closeCurrent
        /// </summary>
        public readonly static string Json结果代码_callbackType_关闭当前对话框 = "closeCurrent";

        public const int 超级管理员角色ID = 1;
    }

    /// <summary>
    /// 操作结果JSON
    /// </summary>
    public class AjaxResult
    {
        /// <summary>
        /// 操作成功
        /// </summary> 
        /// <param name="msg"></param>
        /// <param name="navTabId"></param>
        /// <param name="closeCurrent"></param>
        /// <returns></returns>
        public string Suc(string msg, dynamic attr = null, string data = "")
        {
            var result = new AjaxResult
            {
                statusCode = StatusCode.成功,
                message = msg,
                Attr = attr,
                Data = data
            };
            return result.ToJson();
        }

        /// <summary>
        /// 操作成功
        /// </summary> 
        /// <param name="msg"></param>
        /// <returns></returns>
        public string Suc(string msg)
        {
            var result = new AjaxResult
            {
                statusCode = StatusCode.成功,
                message = msg,
                Attr = Attr,
                Data = Data
            };
            return result.ToJson();
        }

        public string SearchSuc(string msg, string navTabId = "")
        {
            var result = new AjaxResult
            {
                statusCode = StatusCode.查询成功,
                message = msg,
                navTabId = navTabId,
            };
            return result.ToJson();
        }

        public string Err(string msg, string navTabId = "")
        {
            var result = new AjaxResult
            {
                statusCode = StatusCode.错误,
                message = msg,
                navTabId = navTabId,
            };
            return result.ToJson();
        }

        public string TimeOut(string msg = "", string navTabId = "")
        {
            var result = new AjaxResult
            {
                statusCode = StatusCode.超时,
                message = msg == "" ? "登录超时，请重新登录！" : msg,
                navTabId = navTabId,
            };
            return result.ToJson();
        }

        public StatusCode statusCode { get; set; } //301 登录超时  300错误
        public HandelCode HandelCode { get; set; }  //扩展后 需要在AJAXDONE中根据CODE实现JS函数
        public string message { get; set; }
        public string navTabId { get; set; }
        public string rel { get; set; }
        public string reloadID { get; set; }
        public string reloadUrl { get; set; }
        public dynamic Attr { get; set; } //动态属性
        public string Data { get; set; } //存放数据
        public string ToJson()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this);
        }

        public string ToJson(StatusCode statusCode, string message, string Data = "", dynamic Attr = null)
        {
            this.statusCode = statusCode;
            this.message = message;
            this.Data = Data;
            this.Attr = Attr;
            return Newtonsoft.Json.JsonConvert.SerializeObject(this);
        }
    }

    /// <summary>
    /// 操作结果状态码
    /// </summary>
    public enum StatusCode
    {
        [Description("信息")]
        信息 = 100,
        [Description("成功")]
        成功 = 200,
        [Description("查询成功")]
        查询成功 = 201,
        [Description("错误")]
        错误 = 300,
        [Description("超时")]
        超时 = 301,
        [Description("警告")]
        警告 = 400
    }

    /// <summary>
    /// 操作结果执行码
    /// </summary>
    public enum HandelCode
    {
        [Description("刷新全部")]
        刷新全部 = 1,
        [Description("重新登录")]
        重新登录 = 2
    }

    public class ZtreeNode
    {
        public string name { get; set; }
        public dynamic id { get; set; }
        public dynamic pId { get; set; }
        public bool open { get; set; }
        public bool isSelect { get; set; }//是否选中
        public bool isParent { get; set; }
        public bool @checked { get; set; }//true 表示节点的输入框被勾选false 表示节点的输入框未勾选


        //...其它扩展属性见ZTREE API文档
        public bool childOuter { get; set; }    //拖动排序时使用


        //子集
        public dynamic children { get; set; }
        //自定义存放数据
        public dynamic data { get; set; }
    }
}